<?php
 
/**
 * This is the model class for table "rentalproperty".
 *
 * The followings are the available columns in table 'rentalproperty':
 * @property integer $id
 * @property integer $idManagement
 * @property string $AddressOne
 * @property string $AddressTwo
 * @property string $City
 * @property string $State
 * @property string $ZipCode
 * @property string $SoftwareCode
 * @property string $EmailAddress
 * @property integer $ActiveManager
 * @property string $PhoneNumber
 * @property integer $NumberOfUnits
 * @property string $ApplicationDocument
 * @property integer $RulesGracePeriod
 * @property integer $LateFee
 * @property integer $LateFeeFrequency
 * @property string $NameOfDevelopement
 *
 * The followings are the available model relations:
 * @property Fees[] $fees
 * @property Managmentincludeinreport[] $managmentincludeinreports
 * @property Paymentinformation[] $paymentinformations
 * @property Sitemanager $activeManager
 * @property Landlord $idManagement0
 */
class Rentalproperty extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Rentalproperty the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'rentalproperty';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		
		return array(
			array('idManagement, ActiveManager, NumberOfUnits, RulesGracePeriod, LateFee, LateFeeFrequency', 'numerical', 'integerOnly'=>true),
			array('AddressOne, AddressTwo, NameOfDevelopement', 'length', 'max'=>30),
			array('City', 'length', 'max'=>20),
			array('State', 'length', 'max'=>2),
			array('ZipCode, PhoneNumber', 'length', 'max'=>10),
			array('SoftwareCode', 'length', 'max'=>15),
			array('EmailAddress', 'length', 'max'=>45),
			//array('ApplicationDocument', 'length', 'max'=>25),
			 array('ApplicationDocument', 'file', 
			 'types'=>'pdf, doc, docx',
			 'maxSize'=>1024 * 1024 * 2, // 50MB
             'tooLarge'=>'The file was larger than 1MB. Please upload a smaller file.',
			 'allowEmpty'=>1,
			 ),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, idManagement, AddressOne, AddressTwo, City, State, ZipCode, SoftwareCode, EmailAddress, ActiveManager, PhoneNumber, NumberOfUnits, ApplicationDocument, RulesGracePeriod, LateFee, LateFeeFrequency, NameOfDevelopement', 'safe', 'on'=>'search'),
			array('AddressOne, City, State','required'),
			array('idManagement','required','message'=>'Mangement Company can not be blank'),
			//array('idManagement','safe','message'=>'Mangement Company can not be blank'),
			
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'fees' => array(self::HAS_ONE, 'Fees', 'FeesForRentalProperty'),
            'managmentincludeinreports' => array(self::HAS_MANY, 'Managmentincludeinreport', 'idRentalProperty'),
            'paymentinformations' => array(self::HAS_ONE, 'Paymentinformation', 'idRentalProperty'),
            'idManagement0' => array(self::BELONGS_TO, 'Landlord', 'idManagement'),
            'activeManager' => array(self::BELONGS_TO, 'Sitemanager', 'ActiveManager'),
            'rentalunits' => array(self::HAS_MANY, 'Rentalunit', 'idRentalProperty'),
            'sitemanagers' => array(self::HAS_MANY, 'Sitemanager', 'idRentalProperty'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'idManagement' => 'Id Management',
			'AddressOne' => 'Address One',
			'AddressTwo' => 'Address Two',
			'City' => 'City',
			'State' => 'State',
			'ZipCode' => 'Zip Code',
			'SoftwareCode' => 'Software Code',
			'EmailAddress' => 'Email Address',
			'ActiveManager' => 'Active Manager',
			'PhoneNumber' => 'Phone Number',
			'NumberOfUnits' => 'Number Of Units',
			'ApplicationDocument' => 'Application Document',
			'RulesGracePeriod' => 'Rules Grace Period',
			'LateFee' => 'Late Fee',
			'LateFeeFrequency' => 'Late Fee Frequency',
			'NameOfDevelopement' => 'Name Of Developement',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('idManagement',$this->idManagement);
		$criteria->compare('AddressOne',$this->AddressOne,true);
		$criteria->compare('AddressTwo',$this->AddressTwo,true);
		$criteria->compare('City',$this->City,true);
		$criteria->compare('State',$this->State,true);
		$criteria->compare('ZipCode',$this->ZipCode,true);
		$criteria->compare('SoftwareCode',$this->SoftwareCode,true);
		$criteria->compare('EmailAddress',$this->EmailAddress,true);
		$criteria->compare('ActiveManager',$this->ActiveManager);
		$criteria->compare('PhoneNumber',$this->PhoneNumber,true);
		$criteria->compare('NumberOfUnits',$this->NumberOfUnits);
		$criteria->compare('ApplicationDocument',$this->ApplicationDocument,true);
		$criteria->compare('RulesGracePeriod',$this->RulesGracePeriod);
		$criteria->compare('LateFee',$this->LateFee);
		$criteria->compare('LateFeeFrequency',$this->LateFeeFrequency);
		$criteria->compare('NameOfDevelopement',$this->NameOfDevelopement,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
	// saving user model history
	
	
}